package com.mall.dao;

import com.mall.domain.FeedBack;
import com.mall.domain.MsAnnouncement;
import com.mall.domain.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 留言类别的持久层接口
 * @author : liangY
 * @date : 2021-01-04 16:48
 */
@Repository
public interface FeedBackDao {

    /**
     * 查询所有留言
     * @param page 分页实体类
     * @return
     */
    @Select("<script>" +
            "select * from tb_feedback where feed_content like #{page.query}" +
            "<if test = \"page.cat_id != null and page.cat_id!=''\">" +
            " and cate_id=#{page.cat_id}" +
            " </if>" +
            " limit #{page.num},#{page.size}" +
            "</script>")
    List<FeedBack> findAll(@Param("page") Page page);
    /**
     * 统计留言信息
     *
     * @return
     */
    @Select("<script>" +
            "select count(*) from tb_feedback where feed_content like #{page.query}" +
            "<if test = \"page.cat_id != null and page.cat_id!=''\">" +
            " and cate_id=#{page.cat_id}" +
            " </if>" +
            "</script>")
    Integer findTotal(@Param("page") Page page);

    /**
     * 更新留言
     * @param itemCat 留言分类实体类
     * @return
     */
    @Update("update tb_feedback set is_show=#{is_show}  where id=#{id}")
    Integer update(FeedBack itemCat);

    /**
     * 添加留言
     * @param itemCat 添加留言
     * @return
     */
    @Insert("insert into tb_feedback (id,user_id,feed_content,user_name,fed_date_time,cate_name,cate_id)" +
            "values(#{id},#{user_id},#{feed_content},#{user_name},#{fed_date_time},#{cate_name},#{cate_id})")
    @SelectKey(keyColumn = "id", keyProperty = "id", resultType = Integer.class,
            before = false, statement = {"select last_insert_id()"})
    Integer addFeedBack(FeedBack itemCat);

    /**
     * 删除留言
     * @param id id
     * @return
     */
    @Delete("delete from tb_feedback where id = #{id}")
    Integer del(Integer id);
}
